<template>
  <basic-container class>
    <dataList
      :pageInfo="pager"
      placeholder="请输入物业名称"
      :listData="tableData"
      :selectData="selectDataArr"
      searchName="propertyName"
      :filterList="filterList"
      :menuList="['add', 'delete', { export: '导出' }]"
      @menu-click="handleMenuClick"
      openSelection
    >
      <el-table :data="tableData" @selection-change="$event => (selectDataArr = $event)" align="left">
        <el-table-column type="selection" width="55" />
        <el-table-column label="物业名称" prop="propertyName" width="200" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.propertyName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="物业小类" :formatter="dictVal_propertyTypes" prop="projectType" />
        <el-table-column label="物业地址" prop="projectAddr" min-width="220" show-overflow-tooltip />
        <el-table-column label="具体位置" prop="address" width="100" show-overflow-tooltip />
        <el-table-column label="巡查人" prop="inspectionPerson" />
        <el-table-column label="实际巡查日期" prop="inspectionDate" width="100" />
        <el-table-column label="巡查结果" prop="inspectionResult">
          <template slot-scope="scope">
            <span :style="{color:(['1','4'].includes(scope.row.inspectionResult)?'red':'#000')}">{{inspectionResultFormatter(scope.row.inspectionResult)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="管理所" prop="manageUnit" :formatter="manageFormatter" show-overflow-tooltip width="100" />
        <el-table-column label="不通过原因" prop="reason" width="150" show-overflow-tooltip />
        <el-table-column label="操作" fixed="right" width="140">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="showDetailsOfInspectionResults('edit',scope.row)" v-show="scope.row.inspectionPerson == user.realName">编辑</el-button>
            <el-button size="mini" type="text" :underline="false" @click="showDetailsOfInspectionResults('view',scope.row)">查看</el-button>
            <el-button size="mini" type="text" :underline="false" @click="$refs.reviewDialog.showDialog(scope.row)" v-if="['1','4'].includes(scope.row.inspectionResult)">复查</el-button>
          </template>
        </el-table-column>
      </el-table>
    </dataList>
    <el-dialog custom-class="small-padding-dialog" :title="title" :visible.sync="dialogVisible" width="80%" @close="close" :close-on-click-modal="false" class="basic-from">
      <div style="font-weight: 700; height: 40px; font-size: 16px;">基本信息</div>
      <el-form ref="resultDetailsForm" :model="resultDetailsForm" :rules="rules" label-width="auto" class="form-wrap" style="padding-top:0px;" label-position="top">
        <el-form-item label="物业名称" prop="roomId">
          <el-select
            v-model="resultDetailsForm.roomId"
            :disabled="title === '查看巡查结果'"
            filterable
            remote
            reserve-keyword
            :remote-method="remotePropertyNameMethod"
            placeholder="输入物业名称关键字获取列表"
            @change="propertyNameMonitoring($event)"
            :loading="loading"
          >
            <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.value">{{ item.label }}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物业地址" prop="projectAddr">
          <el-input v-halfCharCode v-model="resultDetailsForm.projectAddr" placeholder="请输入" :readonly="title === '查看巡查结果'" />
        </el-form-item>
        <el-form-item label="具体位置" prop="address">
          <el-input v-halfCharCode v-model="resultDetailsForm.address" placeholder="请输入" :readonly="title === '查看巡查结果'" />
        </el-form-item>
        <el-form-item label="物业大类" prop="projectType">
          <span v-for="item in getDict('property_types')" :key="item.value">
            <el-input v-halfCharCode readonly v-if="resultDetailsForm.projectType == item.value" v-model="item.label" placeholder="请输入" />
          </span>
        </el-form-item>
        <el-form-item label="物业小类" prop="projectSubclassType">
          <span v-for="item in getDict('property_use_types')" :key="item.value">
            <el-input v-halfCharCode readonly v-if="resultDetailsForm.projectSubclassType == item.value" v-model="item.label" placeholder="请输入" />
          </span>
        </el-form-item>
        <el-form-item label="物业状态" prop="propertyStatus">
          <span v-for="item in getDict('room_status')" :key="item.value">
            <el-input v-halfCharCode readonly v-if="resultDetailsForm.propertyStatus == item.value" v-model="item.label" placeholder="请输入" :readonly="title === '查看巡查结果'" />
          </span>
        </el-form-item>
        <el-form-item label="使用单位" prop="useUnit">
          <el-select v-model="resultDetailsForm.useUnit" :disabled="title === '查看巡查结果'" filterable remote reserve-keyword :remote-method="remoteUseUnitMethod" placeholder="输入单位名称关键字单位列表" :loading="loading">
            <el-option v-for="(item, index) in unitList" :key="index" :label="item.value" :value="item.value">{{ item.value }}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系电话" prop="mobile">
          <el-input v-halfCharCode v-model="resultDetailsForm.mobile" :readonly="['查看巡查结果','编辑巡查结果'].includes(title)" placeholder="请输入手机或座机号码" />
        </el-form-item>
        <el-form-item label="所属管理所" prop="manageUnit">
          <span></span>
          <span v-for="item in getDict('administrative_office')" :key="item.value">
            <span v-if="resultDetailsForm.manageUnit == item.value">{{ item.label }}</span>
          </span>
        </el-form-item>
        <el-form-item label="预计巡查日期" prop="predictInspectionDate">
          <el-date-picker value-format="yyyy-MM-dd" :disabled="title === '查看巡查结果'" v-model="
                                    resultDetailsForm.predictInspectionDate
                                " type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="实际巡查日期" prop="inspectionDate">
          <el-date-picker v-model="resultDetailsForm.inspectionDate" :disabled="title === '查看巡查结果'" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <!--业务要求   巡查人员指定当前登录账号 -->
        <el-form-item label="巡查人员" prop="inspectionPerson">
          <el-input v-model="resultDetailsForm.inspectionPerson" readonly placeholder="请输入" />
        </el-form-item>
        <el-form-item label="巡查参与人员" prop="inspectionOtherPerson">
          <el-input v-model="resultDetailsForm.inspectionOtherPerson" :readonly="title === '查看巡查结果'" placeholder="请输入" />
        </el-form-item>
        <el-tabs v-model="tabTitle" class="full">
          <el-tab-pane label="上报隐患记录" name="上报隐患记录">
            <el-table :data="resultDetailsForm.reportDangerRecord">
              <el-table-column property="inspectionName" align="left" label="检查项目" />
              <el-table-column property="inspectionStandard" align="left" label="检查标准" />
              <el-table-column property="inspectResult" align="left" label="检查结果">
                <template slot-scope="scope">
                  <span v-text="scope.row.inspectResult == '0'? '达标': '未达标'" v-if="title === '查看巡查结果'" />
                  <el-switch v-else v-model="scope.row.inspectResult" active-color="#13ce66" inactive-color="#ff4949" active-value="0" active-text="达标" inactive-text="未达标" inactive-value="1"></el-switch>
                </template>
              </el-table-column>
              <el-table-column property="substandardContents" label="补充说明">
                <template slot-scope="scope">
                  <span v-if="title === '查看巡查结果'">{{scope.row.substandardContents}}</span>
                  <el-input v-else v-halfCharCode v-model="scope.row.substandardContents" placeholder="请输入" />
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
        <el-form-item label="巡查结果" prop="inspectionResult" class="mt20">
          <el-select clearable v-model="resultDetailsForm.inspectionResult" :disabled="title === '查看巡查结果'" filterable placeholder="-=请选择=-">
            <el-option v-for="(item, index) in getDict('inspection_result')" :key="index" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" class="full">
          <el-input v-halfCharCode v-model="resultDetailsForm.remarks" type="textarea" :readonly="title === '查看巡查结果'" maxlength="10" placeholder="请输入" />
        </el-form-item>
        <h3 style="margin-top: 20px;">附件</h3>
        <el-divider class="full"></el-divider>
        <el-form-item v-if="dialogVisible" class="full">
          <v-upload
            type="file"
            hideExplain
            ref="upload"
            :filterList="uploadFileList"
            :busId="resultDetailsForm.resultId"
            modelType="checkin"
            @onSuccess="onSuccess"
            v-model="uploadFileList"
            :canDelete="title==='编辑巡查结果'"
            :isView="title === '查看巡查结果'"
          />
        </el-form-item>
        <h3 class="mt20 full">整改信息</h3>
        <el-divider class="full"></el-divider>
        <el-form-item label="整改意见" class="full">
          <el-input class="full" v-halfCharCode v-model="resultDetailsForm.inspectionLogRectify.opinion" type="textarea" :readonly="title === '查看巡查结果'" maxlength="10" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="附件" class="full">
          <div v-if="dialogVisible">
            <v-upload
              type="file"
              hideExplain
              ref="rectifyUpload"
              :busId="resultDetailsForm.inspectionLogRectify.inspectionLogId"
              modelType="rectify"
              @onSuccess="rectifyOnSuccess"
              v-model="rectifyFileList"
              :canDelete="title==='编辑巡查结果'"
              :isView="title === '查看巡查结果'"
            />
          </div>
        </el-form-item>
      </el-form>
      <div v-if="title === '查看巡查结果'">
        <h3>复查结果</h3>
        <el-divider></el-divider>
        <div class="reviewBox" v-for="(item,index) in resultDetailsForm.inspectionLogRecheck" :key="item.inspectionLogId" style="width:100%;border:1px solid #DCDFE6;">
          <p>复查人：{{item.approvePerson}}</p>
          <p>复查参与人员：{{item.inspectionOtherPerson}}</p>
          <p>复查时间：{{item.approveDate}}</p>
          <p>复查意见：{{item.opinion}}</p>
          <p>
            复查结果：
            <span :style="{color:(['1','4'].includes(item.inspectionResult)?'red':'#000')}">{{inspectionResultFormatter(item.inspectionResult)}}</span>
          </p>
          <p>
            附件：
            <v-upload type="file" hideExplain :busId="item.inspectionLogId" modelType="review" v-model="reviewFileList" isView autoLoadFiles />
          </p>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" align="right">
        <el-button @click="dialogVisible = false">{{title === '查看巡查结果'?'返回':'取消'}}</el-button>
        <el-button type="primary" v-throttle="[save]" v-if="title !== '查看巡查结果'">保存</el-button>
      </div>
    </el-dialog>
    <!-- 复查弹窗 -->
    <review-dialog ref="reviewDialog" />
  </basic-container>
</template>

<script src="./index.js"></script>

<style lang="scss" scoped>
.fl {
  float: left;
}

.fr {
  float: right;
}

.footer {
  overflow: hidden;
}

.header {
  overflow: hidden;
  margin-bottom: 10px;

  .fl {
    width: 60%;
  }
}
.property {
  color: #1b68e8;
  cursor: pointer;
}
.reviewBox {
  padding: 15px;
  margin-bottom: 10px;
  p {
    line-height: 30px;
  }
}
</style>
